package com.ayoka.parenting.ui.meditation.detail;

import android.os.Bundle;
import android.view.View;

import com.ayoka.parenting.R;
import com.ayoka.parenting.bean.MeditationDetailBean;
import com.ayoka.parenting.databinding.FragmentMeditationDetailVideoTypeBinding;
import com.ayoka.parenting.mvp.BasePresenter;
import com.ayoka.parenting.mvp.BaseView;
import com.ayoka.parenting.mvp.MVPBaseFragment;
import com.jincp.image.load.ImageLoader;
import com.jzvd.JZMediaIjkplayer;

import cn.jzvd.JZVideoPlayer;
import cn.jzvd.JZVideoPlayerStandard;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: MeditationActivity.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class MeditationDetailVideoTypeFragment extends MVPBaseFragment<FragmentMeditationDetailVideoTypeBinding, BaseView, BasePresenter> {

    public static MeditationDetailVideoTypeFragment newInstance(MeditationDetailBean meditationDetailBean) {
        MeditationDetailVideoTypeFragment fragment = new MeditationDetailVideoTypeFragment();
        Bundle bundle = new Bundle();
        bundle.putSerializable("MeditationDetailBean", meditationDetailBean);
        fragment.setArguments(bundle);
        return fragment;
    }

    private MeditationDetailBean meditationDetailBean;

    @Override
    protected void configBundleArguments() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            meditationDetailBean = (MeditationDetailBean) bundle.getSerializable("MeditationDetailBean");
        }
    }

    @Override
    protected int getContentLayout() {
        return R.layout.fragment_meditation_detail_video_type;
    }

    @Override
    protected void initViews(View view) {
        // 设置文件播放类型和播放器
        JZVideoPlayer.setVideoImageDisplayType(JZVideoPlayer.VIDEO_IMAGE_DISPLAY_TYPE_FILL_SCROP);
        JZVideoPlayer.setMediaInterface(new JZMediaIjkplayer());
    }

    @Override
    protected void initData() {
        if (meditationDetailBean == null || meditationDetailBean.meditation == null) return;
        // 增加封面
        ImageLoader.getInstance().displayImage(meditationDetailBean.meditation.ImgUrl, mDataBinding.videoPlayer.thumbImageView);
        mDataBinding.videoPlayer.setUp(meditationDetailBean.meditation.MediaUrl, JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, meditationDetailBean.meditation.Title);
        mDataBinding.tvMore.setText(meditationDetailBean.meditation.Descp);
    }

    @Override
    protected BasePresenter getPresenter() {
        return null;
    }

    @Override
    public void onPause() {
        JZVideoPlayer.goOnPlayOnPause();
        super.onPause();
    }

    @Override
    public void onDestroy() {
        JZVideoPlayer.releaseAllVideos();
        super.onDestroy();
    }
}
